#include <REGX52.H>
#include "DELAY.H"
int MatrixKey()
{
	int num=-10;
    while(1)
	{
			P1=0xff;
			P1_3=0;
			if(P1_5==0){	Delay(20);	while(P1_5==0);  num=1; Delay(20);	}
			if(P1_6==0){	Delay(20);	while(P1_6==0);  num=4;	Delay(20);	}
			if(P1_7==0){	Delay(20);	while(P1_7==0);  num=7;	Delay(20);	}

			P1=0xff;
			P1_2=0;
			if(P1_4==0){	Delay(20);	while(P1_4==0);  num=0;	Delay(20);	}
			if(P1_5==0){	Delay(20);	while(P1_5==0);  num=2;	Delay(20);	}
			if(P1_6==0){	Delay(20);	while(P1_6==0);  num=5;	Delay(20);	}
			if(P1_7==0){	Delay(20);	while(P1_7==0);  num=8;	Delay(20);	}

			P1=0xff;
			P1_1=0;
			if(P1_5==0){	Delay(20);	while(P1_5==0);  num=3;	Delay(20);	}
			if(P1_6==0){	Delay(20);	while(P1_6==0);  num=6;	Delay(20);	}
			if(P1_7==0){	Delay(20);	while(P1_7==0);  num=9;	Delay(20);	}
			
			P1=0xff;
			P1_0=0;
			if(P1_5==0){	Delay(20);	while(P1_5==0);  num=-1;	Delay(20);	}//-1代表取消
			if(P1_6==0){	Delay(20);	while(P1_6==0);  num=-2;	Delay(20);	}//-2代表确定
			if(P1_7==0){	Delay(20);	while(P1_7==0);  num=-3;	Delay(20);	}//-3代表撤销
			
			if(num!=-10)
			{
				return num;
			}
		}		
}
